<%@ taglib prefix="app" uri="/app-tags"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%@ taglib prefix="sec" uri="http://www.springframework.org/security/tags"%>
<%@ taglib prefix="tiles" uri="http://tiles.apache.org/tags-tiles" %>

<tiles:insertTemplate template="/tiles/layout.jsp">
	<tiles:putAttribute name="selected" value="planes" />
	<tiles:putAttribute name="submenu">
		<ul>
			<sec:authorize access="hasRole('ROLE_ADMIN')">
			<li><a href="${pageContext.request.contextPath}/planes/nuevo-plan.action" class="pagenew">Nuevo Plan</a></li>
			<li><a href="${pageContext.request.contextPath}/planes/liquidar.action" class="pagenew">Liquidar Planes</a></li>
			</sec:authorize>
		</ul>
	</tiles:putAttribute>
	
	<tiles:putAttribute name="body">
		
		<div id="rightnow">
			<h3 class="reallynow">
				<span>Plan - Responsable <c:out value="${plan.responsable.nombre}"/></span>
				
				<br />
			</h3>
		</div>
		
 		<div id="infowrap"> 
			<div id="infobox" class="margin-left">
				<h3>Detalle del plan</h3>
				<table> 
					<thead>
					</thead>
					<tbody>
						<tr><td>Monto total</td><td>$<c:out value="${plan.monto}"/></td></tr>
						<tr><td>Cuotas</td><td><c:out value="${plan.cantCuotas}"/></td></tr>
						<tr><td>Saldo plan</td><td>$<c:out value="${plan.saldoPlan}"/></td></tr>
						<tr><td>Saldo intereses</td><td>$<c:out value="${plan.saldoIntereses}"/></td></tr>
					</tbody>
				</table>
			</div>
		</div>
		
		<c:if test="${plan.saldoPlan >  0 }">
		<div id="infowrap"> 
			<div id="infobox" class="margin-left">
				<h3>Registrar cobro</h3>
				<table> 
					<thead>
					</thead>
					<tbody>
						<tr><td>
						
						<img src="${pageContext.request.contextPath}/img/icons/cash_register.png" title="Detalle" width="16" height="16" />
						<a href="${pageContext.request.contextPath}/planes/cobro.action?plan.id=${plan.id}">Registrar cobro</a>
						
						
						</td></tr>
					</tbody>
				</table>
			</div>
		</div>
		</c:if>
		
		<div id="clear"></div>
		<div id="infowrap">		
			<app:tablefilter tableId="liquidaciones"></app:tablefilter>
			<div id="infobox" class="margin-left">
			<h3>Liquidaciones</h3>
			</div>
					<div id="clear"></div>
			<table id="liquidaciones" width="100%">
				<thead>
					<tr>
						<th width="40px">N&uacute;mero</th>
						<th>Periodo</th>
						<th>Monto</th>
						<th>Intereses</th>
						<th>Punitorio</th>
						<th>Int 2do Venc</th>
						<th>Vencimiento</th>
						<th>Acciones</th>
					</tr>
				</thead>
				<tbody>
					<c:forEach var="liquidacion" items="${plan.liquidaciones}">
						<tr>
							<td><c:out value="${liquidacion.numero}" /></td>
							<td><fmt:formatDate pattern="MMMM 'de' yyyy" value="${liquidacion.periodo}" /></td>
							<td>$<c:out value="${liquidacion.monto}" /></td>
							<td>$<c:out value="${liquidacion.interesesFinancieros}" /></td>
							<td>$<c:out value="${liquidacion.interesesPunitorios}" /></td>
							<td>$<c:out value="${liquidacion.interes2Vto}" /></td>
							<td><fmt:formatDate pattern="dd/MM/yyyy" value="${liquidacion.vencimiento1}" /></td>
							<td>
							<a href="${pageContext.request.contextPath}/planes/liquidacion-cobro.action?liquidacion.id=${liquidacion.id}">
							<img src="${pageContext.request.contextPath}/img/icons/report.png" title="Detalle" width="16" height="16" /></a>
							</td>
						</tr>
					</c:forEach>
				</tbody>
			</table>
		</div>
		
		<div id="clear"></div>
		<div id="infowrap">		
			<app:tablefilter tableId="cobros"></app:tablefilter>
			<div id="infobox" class="margin-left">
			<h3>Cobros</h3>
			</div>
			<div id="clear"></div>
			<table id="cobros" width="100%">
				<thead>
					<tr>
						<th width="40px">N&uacute;mero</th>
						<th>Fecha</th>
						<th>Monto</th>
						<th>Intereses</th>
						<th width="80px">Acciones</th>
					</tr>
				</thead>
				<tbody>
					<c:forEach var="cobro" items="${plan.cobros}">
						<tr>
							<td><c:out value="${cobro.numero}" /></td>
							<td><fmt:formatDate pattern="dd/MM/yyyy" value="${cobro.fecha}" /></td>
							<td>$<c:out value="${cobro.monto}" /></td>
							<td>$<c:out value="${cobro.interesesFinancieros}" /></td>
							
							<td>
							<a href="${pageContext.request.contextPath}/planes/detalle-cobro.action?cobro.id=${cobro.id}">
							<img src="${pageContext.request.contextPath}/img/icons/report.png" title="Detalle" width="16" height="16" /></a>
							
							<c:if test="${cobro.consolidado == false}">
								
							<a href="${pageContext.request.contextPath}/planes/borrar.action?cobro.id=${cobro.id}&plan.id=${plan.id}">
							<img src="${pageContext.request.contextPath}/img/icons/calculator_delete.png" title="Borrar Cobro" width="16" height="16" /></a>
							
							<sec:authorize access="hasRole('ROLE_ADMIN')">
								<a href="${pageContext.request.contextPath}/planes/consolidar.action?cobro.id=${cobro.id}">
								<img src="${pageContext.request.contextPath}/img/icons/stamp.png" title="Consolidar Cobro" width="16" height="16" /></a>
							</sec:authorize>
							
							</c:if>
							
							</td>
							
						</tr>
					</c:forEach>
				</tbody>
			</table>
		</div>
 
	</tiles:putAttribute>
</tiles:insertTemplate>